package mysql

import (
	"fmt"
	_ "github.com/go-sql-driver/mysql"
)

type RuleStruct struct {
	Rule_id   int
	Rule_name string
}

func MysqlDemoQuery() {

	db := mysql_conn

	sql := "select rule_id,rule_name from duty_rule where state = ?"
	stmt, err := db.Prepare(sql)
	if err != nil {
		panic(err)
	}
	res, err := stmt.Query(1)

	if err != nil {
		panic(err)
	}

	var rules []RuleStruct

	for res.Next() {
		var id int
		var name string
		err := res.Scan(&id, &name)
		if err != nil {
			panic(err)
		}
		var item RuleStruct
		item.Rule_id = id
		item.Rule_name = name
		rules = append(rules, item)
	}

	fmt.Println(rules)
}
